<?php
namespace Home\Controller;
use Think\Controller;
class UsersController extends Controller{
	public function UserLogin(){
		$this->display('Index');
	}
	public function belverify(){
		$config =array(  
			'fontSize'    =>   	20,    // 验证码字体大小    
			'length'      =>    4,     // 验证码位数    
			'useNoise'    =>    true, // 关闭验证码杂点
			);
		$Verify =new \Think\Verify($config);
		$Verify->entry();
	}
	public function login(){
		$userInfo = D("Users")->loginUser();
		$belver = I( "post.checke" );
	 	$verify = new \Think\Verify(); 
		if($verify->check($belver)){
			if( $userInfo['status']==1){
				$this->success( "登陆成功",U("Index/index"));
			}elseif($userInfo['status']==2){
				$this->error('账号密码错误');
			}else{
				$this->error('用户名不存在');
			}
		}else{
			$this->error( "验证码错误" );
		}
	}
	//登出	
	public function clearUser(){
    	session(null);
    	if(empty($_SESSION)){
    		$this->success('注消成功',"Userlogin");
    	}else{
    		$this->error('注消失败');
    	}
    }
    public function register(){
    	$this->display('userreg');
    }
    
    //用记注册
    
    public function Usersreg(){
    	$UsersModel=D('users');
    	if($UsersModel->UsersReg()){
    		$data['status']=1;
    	}else{
    		$data['status']=2;
    	}
    	$this->ajaxReturn($data);
    }
    
    //验证用户是否存在
    public function HasUsers(){
    	$uname=I("post.uname")?I("post.uname"):'';
    	if($uname==''){
    		$data['status']=3;
    	}else{
    		$UserModel=D('Users');
    		if($userList=$UserModel->hasUser($uname)){
    			$data['status']=1;
    		}else{
    			$data['status']=2;
    		}
    	}
    	$this->ajaxReturn($data);
    }
    
    
    public function touxiang(){
		$this->display('touxiang');
	}
    public function upload(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/Users/'; // 设置附件上传根目录
        $upload->saveName  = 	 rand(1000-9000);
        // 上传文件 
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
          $this->error($upload->getError());
        }else{// 上传成功
           foreach($info as $file){
		      	$data['imgpath']=$upload->rootPath.$file['savepath'].$file['savename'];
		      	$touxiangModel=M('touxiang');
		        if($touxiangModel->add($data)){
		      	  	echo'上传成功';
		      	}else{
		      		echo '上传失败';
		      	}
	   		}
        }
	}
} 


?>